export default {
	namespaced: true,
	state: () => ({
		recruitList: JSON.parse(uni.getStorageSync('recruitCollect') || '[]'),
		parttimeList: JSON.parse(uni.getStorageSync('parttimeCollect') || '[]'),
		commpanyList: JSON.parse(uni.getStorageSync('commpanyCollect') || '[]'),
	}),
	mutations: {

		// 追加收藏
		setRecruitList(state, item) {
			var index = state.recruitList.findIndex(list => list.id === item.id)
			// 无重复才添加
			if (index < 0) {
				state.recruitList.unshift(item)
				this.commit('m_collect/saveRecruitStorage')
			}
		},
		setParttimeList(state, item) {
			var index = state.parttimeList.findIndex(list => list.id === item.id)
			// 无重复才添加
			if (index < 0) {
				state.parttimeList.unshift(item)
				this.commit('m_collect/saveParttimeStorage')
			}

		},
		setCommpanyList(state, item) {
			var index = state.commpanyList.findIndex(list => list.id === item.id)
			// 无重复才添加
			if (index < 0) {
				state.commpanyList.unshift(item)
				this.commit('m_collect/saveCommpanyStorage')
			}

		},

		// 取消收藏
		delRecruitList(state, list) {
			state.recruitList = state.recruitList.filter(item => item.id !== list.id)
			this.commit('m_collect/saveRecruitStorage')

		},
		delParttimeList(state, list) {
			state.parttimeList = state.parttimeList.filter(item => item.id !== list.id)
			this.commit('m_collect/saveParttimeStorage')

		},
		delCommpanyList(state, list) {
			state.commpanyList = state.commpanyList.filter(item => item.id !== list.id)
			this.commit('m_collect/saveCommpanyStorage')

		},

		// 本地存储
		saveRecruitStorage(state) {
			uni.setStorageSync('recruitCollect', JSON.stringify(state.recruitList));

		},
		saveParttimeStorage(state) {
			uni.setStorageSync('parttimeCollect', JSON.stringify(state.parttimeList));
		},
		saveCommpanyStorage(state) {
			uni.setStorageSync('commpanyCollect', JSON.stringify(state.commpanyList));
		},

		// 清空收藏
		clearCollects(state) {
			uni.setStorageSync('recruitCollect', '[]');
			uni.setStorageSync('parttimeCollect', '[]');
		}

	},
	getters: {}
}
